//
//  DelayedLoadingViewController.m
//  iPhoneMyRailApp
//
//  Created by Christopher Anderson on 01/11/2008.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "DelayedLoadingViewController.h"
#import "LoadingContentTableDelegater.h"
#import "InformationReportingTableDelegate.h"

@implementation DelayedLoadingViewController

@synthesize myTableView, loadingTableDelegate, informationReportingTableDelegate, header, headerIndent, queue;


// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad.
- (void)viewDidLoad  {
 
		self.loadingTableDelegate = [[LoadingContentTableDelegater alloc] init];
		self.informationReportingTableDelegate = [[InformationReportingTableDelegate alloc] init];
		self.queue = [[NSOperationQueue alloc] init];
		[queue setMaxConcurrentOperationCount:1];
	
    
}

- (void) startBackgroundOperation {
	[self setLoadingDelegateForTableView];
	
	// Stop any exising lookups
	[queue cancelAllOperations];

	NSOperation *op = [self getOperation];
	[queue addOperation:op];
	[op release];
	
}

- (NSOperation*) getOperation {
	return nil;
}

- (void) setLoadingDelegateForTableView {
	self.myTableView.delegate = loadingTableDelegate;
	self.myTableView.dataSource = loadingTableDelegate;
	[myTableView reloadData];
}


- (void) setInformationReportDelegateForTableView:(NSString*)report {
	[informationReportingTableDelegate setReport:report];
	self.myTableView.delegate = informationReportingTableDelegate;
	self.myTableView.dataSource = informationReportingTableDelegate;
	[myTableView reloadData];
}

- (void) reportConnectionProblem {
	[self setInformationReportDelegateForTableView:@"Sorry, unable to connect to live info at the moment. Please try again soon."];
}

- (void) restoreTableDelegate {
	self.myTableView.delegate = self;
	self.myTableView.dataSource = self;
	[myTableView reloadData];
}


/*
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
	NSLog(@"Orientation change in Delayed Controlelr");
	if (fromInterfaceOrientation == UIInterfaceOrientationPortrait  || fromInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {
		if (realTimeTicker == nil) {
			realTimeTicker = [[RealTimeTicker alloc] initWithNibName:@"RealTimeTicker" bundle:nil];
		}
		[[self navigationController] presentModalViewController:realTimeTicker animated:YES];
		//[[self navigationController] pushViewController:realTimeTicker animated:YES];		
	}
}
*/


- (void)dealloc {
	[header release];
	[loadingTableDelegate release];
    [super dealloc];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
	return nil;
}

- (void)didReceiveMemoryWarning {
	// Accoring to the docs if the View and View controller are in the nib you should not 
	// call the next line. If we call the next line and you get a memory warning on a page
	// 2 away from the root (e.g. Root -> DAB -> Calling Pattern) you will not be able
	// to get back to the root.
	//  [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

@end
